//
//  SingerViewController.m
//  NhomThuy02
//
//  Created by Nguyễn Hoàng Dũng on 2/2/15.
//  Copyright (c) 2015 LamQuoc. All rights reserved.
//

#import "SingerViewController.h"
#import "ManagerData.h"
#import "SingerViewCell.h"
#import "SongBySingerViewController.h"
@interface SingerViewController ()<UICollectionViewDataSource,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end

@implementation SingerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.cvSingerList.delegate = self;
    self.cvSingerList.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden=NO;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [ManagerData defaultManager].singerList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID =@"singer_cell_id";
    SingerViewCell *cell;
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    if (!cell) {
        [collectionView registerClass:[SingerViewCell class] forCellWithReuseIdentifier:cellID];
    }
   
    NSDictionary *singer = [[ManagerData defaultManager].singerList objectAtIndex:indexPath.item];
    cell.imgvSingerImage.image = [UIImage imageNamed:[singer objectForKey:@"singer-avatar"]];
    cell.lbSingerName.text = [singer objectForKey:@"singer-name"];
    [cell.lbSingerName setBackgroundColor: [UIColor greenLightColor]];
    return cell;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((collectionView.frame.size.width-12)/3, 125);
}
#pragma mark UICollectionView
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"song_by_singer_push"]){
        SongBySingerViewController *song = segue.destinationViewController;
        NSIndexPath *selectItem =self.cvSingerList.indexPathsForSelectedItems[0];
        song.singer = [[ManagerData defaultManager].singerList objectAtIndex:selectItem.item];
    }
}
@end
